package cn.com.lms.business.exam.service;

import cn.com.lms.app.api.exam.vo.TestLearnStageDetailVO;
import cn.com.lms.business.exam.persistence.entity.EmployeePaperStage;
import cn.com.lms.business.exam.persistence.repository.EmployeePaperStageRepository;
import cn.com.lms.business.exam.utils.JsonUtil;
import cn.com.lms.business.learning.persistence.repository.LearningStageDetailRepository;
import com.bnzj.core.persistence.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;


@Service
public class EmployeePaperStageService extends BaseService<EmployeePaperStageRepository, EmployeePaperStage, Long> {

    @Autowired
    LearningStageDetailRepository learningStageDetailRepository;

    public Optional<EmployeePaperStage> findByStageDetailIdAndEmployeeId(Long stageDetailId, Long employeeId) {
        EmployeePaperStage entity = new EmployeePaperStage();
        entity.setEmployeeId(employeeId);
        entity.setStageDetailId(stageDetailId);
        return super.findOne(entity);
    }

    public List<Map> findEmployeePaperByStageDetailIdAndEmployeeId(Long stageDetailId, Long employeeId) {
        return repository.findEmployeePaperByStageDetailIdAndEmployeeId(stageDetailId, employeeId);
    }


    public Map findPassEmployeePaperByStageDetailIdAndEmployeeId(Long stageDetailId, Long employeeId) {
        return repository.findPassEmployeePaperByStageDetailIdAndEmployeeId(stageDetailId, employeeId);
    }

    public Map findNotPassEmployeePaperByStageDetailIdAndEmployeeId(Long stageDetailId, Long employeeId) {
        return repository.findNotPassEmployeePaperByStageDetailIdAndEmployeeId(stageDetailId, employeeId);
    }

    public Map findEmployeePaperByEmployeePaperId(Long employeePaperId) {
        return repository.findEmployeePaperByEmployeePaperId(employeePaperId);
    }

    /**
     * 测验阶段详情
     *
     * @param stageDetailId
     * @return
     */
    public TestLearnStageDetailVO getTestLearningStageDetail(Long stageDetailId) {
        TestLearnStageDetailVO testLearnStageDetailVO = null;
        Map map = learningStageDetailRepository.getTestLearningStageDetail(stageDetailId);
        if (map.size() > 0) {
            testLearnStageDetailVO = JsonUtil.fromMap(map, TestLearnStageDetailVO.class);
        }

        return testLearnStageDetailVO;
    }


}
